﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HomePage.Controllers;
using PortalNews.BUS;
using TGVR_Project.Models;
using PortalNews.DAO;
using System.Web.SessionState;
using MDF.Logger.Managements;
using TGVR_Report;


namespace TGVR_Project.Controllers
{
    
    public class HomeController : BaseController
    {
        public string SaveEmail(string id = "")
        {
            int ia = id.IndexOf('@');
            id = id.Replace('-', '.');
            int ic = id.IndexOf('.');
            if (ia == -1 || ic == -1)
            {
                return id + ":" + m_lang.NOTEMAIL;
            }
            EmailDAO eDAO = new EmailDAO();
            LogManager.GetInstance().Info(string.Format("[{0}] save mail {1}", HttpContext.Request.UserHostAddress, id));
            if (eDAO.Insert(id))
                return m_lang.SUCCESS;
            else
                return m_lang.EXISTEDEMAIL;
        }
        
        public ActionResult Index(FlightSearchModelView viewModel)
        {
            LogManager.GetInstance().Info(string.Format("[{0}] request home page",HttpContext.Request.UserHostAddress));
            NewsBUS nBUS = new NewsBUS();
            ViewBag.LatestNews = nBUS.GetlatestNews(m_lang.iLang, 4);
            ViewBag.LatestPinNews = nBUS.GetlatestPinedNews(m_lang.iLang, 2);
            ViewBag.Title = m_seo.Title;
          
            return View(viewModel);
        }

        public ActionResult About()
        {
            //window
            ViewData["modal"] = false;
            ViewData["scrolling"] = true;
            ViewData["resizable"] = true;
            ViewData["movable"] = true;
            //auto fill
            List<string> lst = new List<string>();
            lst.Add("test");
            lst.Add("Duc");
            ViewData["CitySearch"] = lst;
            ViewBag.Title = "Gioi thieu " + m_seo.Title;
            return View();
        }

        public ActionResult Error()
        {
            return View();
        }

        public ActionResult Test()
        {
            return View();
        }

    
    }
}
